﻿app.controller('MessageController', function ($scope, $rootScope, messageFactory, notificationFactory) {

    init();

    //all implement data model call in a init() function
    function init() {
        $scope.roleByGroup = JSON.parse(localStorage.getItem("menu"));
        $scope.userName = $rootScope.userName;
        //count--------------
        notificationFactory.countAddFriend(localStorage.getItem("idkey")).success(function (data) {
            $scope.countAddFriend = data;
        });
        notificationFactory.countFromRoom(localStorage.getItem("idkey")).success(function (data) {
            $scope.countFromRoom = data;
        });
        notificationFactory.countNewMessage(localStorage.getItem("idkey")).success(function (data) {
            $scope.countNewMessage = data;
        });
        messageFactory.getMessageByFriend(localStorage.getItem("idkey")).success(function (data) {
            $scope.MessageByUser = data;
        });
        $scope.ready = true;
        var dataPost = {
            CommentText: "test",
            CreateBy: "admin",
            RoomId: 1,
            DateTime: null,
            UserId: 1
        };

        $scope.createComment = function () {
            messageFactory.addMessage()
            .success(function () {
                alert('ok');
            }).
            error(function () { });
        };
    }
});